using UnityEngine;

public class daily_item : MonoBehaviour
{
	public int dailyitemnum;

	public UILabel infolabel;

	public UISprite scrollsp;

	public UILabel scrolllabel;

	public UIWidget notfinishwi;

	public UISprite rewardflag;

	public UILabel rewardlabel;

	public UISprite claimsp;

	public UIWidget finishwi;

	public UIEventListener claimbtn;

	public UISprite finishsp;

	public TweenScale completeanima;

	private DailyData curdailydata;

	private int daytaskitem;

	private int[] finishNum = new int[7]
	{
		6,
		3,
		2,
		3,
		1,
		20,
		10
	};

	private bool isclick;

	private bool isfinish;

	private void Start()
	{
		claimbtn.onClick = OnClickclaimBtn;
	}

	public bool enable(int ind)
	{
		dailyitemnum = ind;
		daytaskitem = MenuPlayerprefs.instance.daytask_item[ind];
		if (daytaskitem != -1 && ind == 0)
		{
			daytaskitem = MenuPlayerprefs.instance.readdaytask_zero();
		}
		if (daytaskitem != -1 && ind == 6)
		{
			daytaskitem += (int)Time.time;
			daytaskitem /= 60;
		}
		curdailydata = MenuDataController.instance.DayData[ind];
		isclick = false;
		isfinish = false;
		showinfo();
		return isfinish;
	}

	public void showinfo()
	{
		infolabel.text = curdailydata.docstr;
		if (daytaskitem == -1)
		{
			scrollsp.fillAmount = 1f;
			scrolllabel.text = finishNum[dailyitemnum] + "/" + finishNum[dailyitemnum];
			finishwi.alpha = 1f; finishwi.gameObject.SetActive(true);
			if (isclick)
			{
				completeanima.PlayForward();
			}
			notfinishwi.alpha = 0f; notfinishwi.gameObject.SetActive(false);
			finishsp.enabled = false;
		}
		else
		{
			scrollsp.fillAmount = (float)daytaskitem / (float)finishNum[dailyitemnum];
			scrolllabel.text = daytaskitem + "/" + finishNum[dailyitemnum];
			finishwi.alpha = 0f; finishwi.gameObject.SetActive(false);
			notfinishwi.alpha = 1f; notfinishwi.gameObject.SetActive(true);
			switch (curdailydata.rewardtype)
			{
				case 0:
					rewardflag.spriteName = "GY_zuanShi_01";
					break;
				case 1:
					rewardflag.spriteName = "CZ_jinBi_02";
					break;
			}
			rewardlabel.text = string.Empty + curdailydata.rewardnum;
			if (finishNum[dailyitemnum] <= daytaskitem)
			{
				claimsp.spriteName = "JS_anNiu";
				finishsp.enabled = true;
				isfinish = true;
			}
			else
			{
				claimsp.spriteName = "JS_anNiuHui";
				finishsp.enabled = false;
			}
		}
		isclick = false;
	}

	public void OnClickclaimBtn(GameObject btn)
	{
		if (finishNum[dailyitemnum] <= daytaskitem)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_getmoney, 0f);
			MenuPlayerprefs.instance.setdailytask(dailyitemnum, -1);
			switch (curdailydata.rewardtype)
			{
				case 0:
					MenuPlayerprefs.instance.AddDiamod(curdailydata.rewardnum, late: true);
					MenuUIController.instance.enable_effectui(rewardflag.transform.position, 1);
					MonoInstance<AudioController>.instance.play(AudioType.UI_getdiamond, 0f);
					break;
				case 1:
					MenuPlayerprefs.instance.AddMoney(curdailydata.rewardnum, late: true);
					MenuUIController.instance.enable_effectui(rewardflag.transform.position, 0);
					MonoInstance<AudioController>.instance.play(AudioType.UI_getmoney, 0f);
					break;
			}
			daytaskitem = -1;
			isclick = true;
			isfinish = false;
			showinfo();
			Platform.flurryEvent_dailytask(dailyitemnum);
		}
		else
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_pophit, 0f);
		}
	}
}
